package com.sudoku.entity;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.sudoku.utility.Constants;
import com.sudoku.utility.Locator;

public class GraphicsComponent implements Constants {

	protected Sprite sprite;
	protected float direction;
	protected float scale;
	protected Vector2 position;

	public GraphicsComponent(Vector2 pos, String path, float scale) {
		sprite = new Sprite(Locator.getAssets().get(path, Texture.class));
		direction = 0;
		this.position = pos;
		this.scale = scale;
	}

	public void render(SpriteBatch sb, Entity entity) {
		sb.draw(sprite.getTexture(), entity.renderXPosition(), entity.renderXPosition(), sprite.getWidth() * 0.5f, sprite.getHeight() * 0.5f,
				sprite.getWidth(), sprite.getHeight(), SCALE * scale, SCALE * scale, 0, 0, 0,
				(int) sprite.getWidth(), (int) sprite.getHeight(), false, false);
	}

	public void render(SpriteBatch sb, Sprite sp, Entity entity) {
		sb.draw(sp.getTexture(), entity.renderXPosition(), entity.renderYPosition(), sp.getWidth() * 0.5f, sp.getHeight() * 0.5f, sp.getWidth(),
				sp.getHeight(), SCALE * scale, SCALE * scale, 0, 0, 0, (int) sp.getWidth(),
				(int) sp.getHeight(), false, false);
	}

	// this render function renders sprites with an alpha
	public void render(SpriteBatch sb, float alpha, Entity entity) {
		sb.setColor(sb.getColor().r, sb.getColor().g, sb.getColor().b, alpha);
		sb.draw(sprite.getTexture(), entity.renderXPosition(), entity.renderYPosition(), sprite.getWidth() * 0.5f, sprite.getHeight() * 0.5f,
				sprite.getWidth(), sprite.getHeight(), SCALE * scale, SCALE * scale, 0, 0, 0,
				(int) sprite.getWidth(), (int) sprite.getHeight(), false, false);
		sb.setColor(sb.getColor().r, sb.getColor().g, sb.getColor().b, 1.0f);
	}

	public void dispose() {
		sprite.getTexture().dispose();
	}

	public Vector2 getPosition() {
		return position;
	}

	public float getDirection() {
		return direction;
	}

	public void setPosition(Vector2 position2) {
		position.set(position2);
	}

	public void setDirection(float direction2) {
		direction=direction2;
	}

	public void setSprite(Sprite sprite2) {
		sprite=sprite2;
	}

	public Sprite getSprite() {
		return sprite;
	}
}
